# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/2/8 9:54
# @Author  : qiaoc
# @File    : OcrDataProcess.py
# @Desc    : OCR数据处理类
from decimal import Decimal

class OcrDataProcess:
    """
        OCR数据处理类
    """
    def __init__(self, methodName):
        pass

    def nm_125(datas):
        """
            重复数据处理 -- nm_125
        :param all_save_data:
        :return:
        """
        dict = {}
        result_data = []
        for data in datas:
            if dict.get(data[0]):
                old_data = dict.get(data[0])
                # 计算电价
                if data[2] and data[2] != old_data[2] and data[2] != '':
                   ele_price = Decimal(old_data[2]) + Decimal(str(data[2]).replace('-',''))
                else:
                    ele_price = old_data[2]

                # 总结算电量
                if data[3] and data[3] != old_data[3] and data[3] != '':
                   ele_energy_loss = Decimal(old_data[3]) + Decimal(str(data[3]).replace('-',''))
                else:
                    ele_energy_loss = old_data[3]

                # 总结算电费
                if data[4] and data[4] != '':
                   old_ele_charge = str(data[4]).replace('-','')
                   ele_charge = Decimal(old_data[4]) - Decimal(old_ele_charge)
                else:
                    ele_charge = old_data[4]

                old_data[2] = str(ele_price)
                old_data[3] = str(ele_energy_loss)
                old_data[4] = str(ele_charge)
                result_data.append(old_data)
            else:
                dict[data[0]] = data
        return result_data

    def nm_016(datas):
        """
            处理倍率，如果未空，倍率为1
        :return:
        """
        result_data = []
        for data in datas[3:]:
            if not data[9] and data[9] == '':
                data[9] = 1
            result_data.append(data)
        return result_data
